package com.jsbs.iam.auth.controller;

import com.jsbs.iam.auth.feign.IamRoleManagerFeign;
import com.jsbs.iam.auth.param.IamUserTypeExtendFieldsParam;
import com.jsbs.iam.auth.service.IamUserTypeService;
import com.jsbs.iam.auth.vo.IamUserTypeBaseVo;
import com.jsbs.iam.auth.vo.IamUserTypeExtendedFieldVo;
import com.jsbs.iam.common.core.dto.Result;
import com.jsbs.iam.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: IamUserTypeController
 * @Author: tenghuawei
 * @Date: 2023/1/9 10:57
 * @Description:
 */

@Slf4j
@RestController
@RequestMapping("/iam/auth/userType")
public class IamUserTypeController extends BaseController{

    @Autowired
    IamUserTypeService iamUserTypeService;

    @Autowired
    IamRoleManagerFeign iamRoleManagerFeign;

    /**
     * 功能描述：查询当前登录用户归属租户的——>用户类型
     * @param
     * @return Result
     */
    @PostMapping("/queryUserType")
    public Result queryUserType() {
        try {
            List<IamUserTypeBaseVo> iamUserTypeBaseVos = iamUserTypeService.queryUserTypeList();
            return Result.success("查询用户类型成功！",iamUserTypeBaseVos);
        }catch (Exception e){
            log.error("Route=>IamUserTypeController method=>queryUserType 查询用户类型异常：{}", e.getMessage());
            return handleException(e,e.getMessage());
        }
    }

    /**
     * 功能描述：根据用户类型编码，查扩展字段表
     * @param iamUserTypeExtendFieldsParam
     * @return Result
     */
    @PostMapping("/getUserTypeExtend")
    public Result getUserTypeExtend(@RequestBody IamUserTypeExtendFieldsParam iamUserTypeExtendFieldsParam) {
        try {
            if(StringUtils.isBlank(iamUserTypeExtendFieldsParam.getUserTypeCode())){
                return Result.failWithMsg("用户类型编码不可为空！");
            }
            Result<List<IamUserTypeExtendedFieldVo>> userTypeExtend = iamRoleManagerFeign.getUserTypeExtend(iamUserTypeExtendFieldsParam.getUserTypeCode());
            return Result.success("根据用户类型编码，查扩展字段表成功！",userTypeExtend);
        }catch (Exception e){
            log.error("Route=>IamUserTypeController method=>queryUserType 查询用户类型异常：{}", e.getMessage());
            return handleException(e,e.getMessage());
        }
    }





}
